Page({
  data: {
    deviceNo: '',
    managerName: '',
    managerId: '',
    loading: false
  },

  onLoad() {
    this.getDeviceInfo()
  },

  // 获取设备信息
  getDeviceInfo() {
    const that = this
    that.setData({ loading: true })
    
    // TODO: 调用获取设备信息的API
    setTimeout(() => {
      that.setData({
        loading: false,
        deviceNo: '2507240284',
        managerName: '杨效应测试',
        managerId: '303'
      })
    }, 500)
  },

  // 扫描二维码
  onScanQRCode() {
    const that = this
    wx.scanCode({
      success(res) {
        console.log('扫码结果：', res)
        // TODO: 调用绑定设备的API
        wx.showToast({
          title: '绑定成功',
          icon: 'success'
        })
        that.getDeviceInfo()
      },
      fail() {
        wx.showToast({
          title: '扫码失败',
          icon: 'error'
        })
      }
    })
  },

  // 手动输入设备号
  onInputDevice() {
    const that = this
    wx.showModal({
      title: '输入设备号',
      editable: true,
      placeholderText: '请输入设备号',
      success(res) {
        if (res.confirm && res.content) {
          console.log('输入的设备号：', res.content)
          // TODO: 调用绑定设备的API
          wx.showToast({
            title: '绑定成功',
            icon: 'success'
          })
          that.getDeviceInfo()
        }
      }
    })
  },

  // 解除绑定
  onUnbindDevice() {
    const that = this
    wx.showModal({
      title: '提示',
      content: '确定要解除设备绑定吗？',
      success(res) {
        if (res.confirm) {
          // TODO: 调用解除绑定的API
          that.setData({
            deviceNo: '',
            managerName: '',
            managerId: ''
          })
          wx.showToast({
            title: '已解除绑定',
            icon: 'success'
          })
        }
      }
    })
  }
}) 